package com.xiyoukt.springboot.task;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component
public class ScheduleTask {

    private Logger log = LoggerFactory.getLogger(ScheduleTask.class);

    /**
     *  [秒] [分] [时] [日] [月] [周] [年(可选)]
     * * ： 表示所有，可以知道具体时间
     * / ：初始值/频率
     * - ：表示一个区间范围
     * , : 只有当前时间符合给到的时间才会执行
     * 可以多个一起指定
     */
//    @Scheduled(cron = "30/5 * * * * *")
//    @Scheduled(cron = "5-10 * * * * *")
//    @Scheduled(cron = "20,40 * * * * *")
//    @Scheduled(cron = "20,40 40/2 * * * *")
    public void task1(){
        log.info("task1 execution");
    }

//    @Scheduled(fixedDelay = 2000)
    public void task2() throws InterruptedException {
        log.info("task2 execution");
        Thread.sleep(1000);
    }

    @Scheduled(fixedRate = 2000)
    public void task3() throws InterruptedException {
        log.info("task3 execution");
        Thread.sleep(5000);
    }

    @Scheduled(fixedRate = 2000)
    public void task4() throws InterruptedException {
        log.info("task4 execution");
        Thread.sleep(1000);
    }

}
